﻿using System;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Collections.Generic;

namespace Bango.WindowsPhone7_5.SDK
{
 
	public class BangoDataContext :  DataContext
	{
		public BangoDataContext()
			: base(BangoConstants.DATABASE_CONNECTION_STRING)
		{
		}

		public Table<StoredProfile> Profiles;
		public Table<StoredEvent> Events;
		public Table<StoredEventParameter> EventParameters;
	}
	
	[Table]
	public class StoredProfile : INotifyPropertyChanged, INotifyPropertyChanging, IBangoPostable
	{  

		#region Columns and Relationships

		private int _profileId;
		[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
		public int ProfileId
		{
			get { return _profileId; }
			set
			{
				if (_profileId != value)
				{
					NotifyPropertyChanging("ProfileId");
					_profileId = value;
					NotifyPropertyChanged("ProfileId");
				}
			}
		}

		private string _applicationChannel;
		[Column]
		public string ApplicationChannel
		{
			get { return _applicationChannel; }
			set
			{
				if (_applicationChannel != value)
				{
					NotifyPropertyChanging("ApplicationChannel");
					_applicationChannel = value;
					NotifyPropertyChanged("ApplicationChannel");
				}
			}
		}

		private string _applicationId;
		[Column]
		public string ApplicationId
		{
			get { return _applicationId; }
			set
			{
				if (_applicationId != value)
				{
					NotifyPropertyChanging("ApplicationId");
					_applicationId = value;
					NotifyPropertyChanged("ApplicationId");
				}
			}
		}

		private string _applicationType;
		[Column]
		public string ApplicationType
		{
			get { return _applicationType; }
			set
			{
				if (_applicationType != value)
				{
					NotifyPropertyChanging("ApplicationType");
					_applicationType = value;
					NotifyPropertyChanged("ApplicationType");
				}
			}
		}

		private string _applicationVersion;
		[Column]
		public string ApplicationVersion
		{
			get { return _applicationVersion; }
			set
			{
				if (_applicationVersion != value)
				{
					NotifyPropertyChanging("ApplicationVersion");
					_applicationVersion = value;
					NotifyPropertyChanged("ApplicationVersion");
				}
			}
		}

		private string _connectionType;
		[Column]
		public string ConnectionType
		{
			get { return _connectionType; }
			set
			{
				if (_connectionType != value)
				{
					NotifyPropertyChanging("ConnectionType");
					_connectionType = value;
					NotifyPropertyChanged("ConnectionType");
				}
			}
		}

		private string _countryISO;
		[Column]
		public string CountryISO
		{
			get { return _countryISO; }
			set
			{
				if (_countryISO != value)
				{
					NotifyPropertyChanging("CountryISO");
					_countryISO = value;
					NotifyPropertyChanged("CountryISO");
				}
			}
		}

		private string _deviceBrand;
		[Column]
		public string DeviceBrand
		{
			get { return _deviceBrand; }
			set
			{
				if (_deviceBrand != value)
				{
					NotifyPropertyChanging("DeviceBrand");
					_deviceBrand = value;
					NotifyPropertyChanged("DeviceBrand");
				}
			}
		}

		private bool _deviceIsMobile;
		[Column]
		public bool DeviceIsMobile
		{
			get { return _deviceIsMobile; }
			set
			{
				if (_deviceIsMobile != value)
				{
					NotifyPropertyChanging("DeviceIsMobile");
					_deviceIsMobile = value;
					NotifyPropertyChanged("DeviceIsMobile");
				}
			}
		}

		private string _deviceMake;
		[Column]
		public string DeviceMake
		{
			get { return _deviceMake; }
			set
			{
				if (_deviceMake != value)
				{
					NotifyPropertyChanging("DeviceMake");
					_deviceMake = value;
					NotifyPropertyChanged("DeviceMake");
				}
			}
		}

		private string _deviceModel;
		[Column]
		public string DeviceModel
		{
			get { return _deviceModel; }
			set
			{
				if (_deviceModel != value)
				{
					NotifyPropertyChanging("DeviceModel");
					_deviceModel = value;
					NotifyPropertyChanged("DeviceModel");
				}
			}
		}

		private string _deviceVersion;
		[Column]
		public string DeviceVersion
		{
			get { return _deviceVersion; }
			set
			{
				if (_deviceVersion != value)
				{
					NotifyPropertyChanging("DeviceVersion");
					_deviceVersion = value;
					NotifyPropertyChanged("DeviceVersion");
				}
			}
		}

		private bool _isRoaming;
		[Column]
		public bool IsRoaming
		{
			get { return _isRoaming; }
			set
			{
				if (_isRoaming != value)
				{
					NotifyPropertyChanging("IsRoaming");
					_isRoaming = value;
					NotifyPropertyChanged("IsRoaming");
				}
			}
		}

		private bool _isPosting = false;
		[Column]
		public bool IsPosting
		{
			get { return _isPosting; }
			set
			{
				if (_isPosting != value)
				{
					NotifyPropertyChanging("IsPosting");
					_isPosting = value;
					NotifyPropertyChanged("IsPosting");
				}
			}
		}

		private string _locationCountryISO;
		[Column]
		public string LocationCountryISO
		{
			get { return _locationCountryISO; }
			set
			{
				if (_locationCountryISO != value)
				{
					NotifyPropertyChanging("LocationCountryISO");
					_locationCountryISO = value;
					NotifyPropertyChanged("LocationCountryISO");
				}
			}
		}

		private string _locationRegion;
		[Column]
		public string LocationRegion
		{
			get { return _locationRegion; }
			set
			{
				if (_locationRegion != value)
				{
					NotifyPropertyChanging("LocationRegion");
					_locationRegion = value;
					NotifyPropertyChanged("LocationRegion");
				}
			}
		}

		private string _locationSource;
		[Column]
		public string LocationSource
		{
			get { return _locationSource; }
			set
			{
				if (_locationSource != value)
				{
					NotifyPropertyChanging("LocationSource");
					_locationSource = value;
					NotifyPropertyChanged("LocationSource");
				}
			}
		}

		private string _locationTown;
		[Column]
		public string LocationTown
		{
			get { return _locationTown; }
			set
			{
				if (_locationTown != value)
				{
					NotifyPropertyChanging("LocationTown");
					_locationTown = value;
					NotifyPropertyChanged("LocationTown");
				}
			}
		}

		private double _locationAccuracy;
		[Column]
		public double LocationAccuracy
		{
			get { return _locationAccuracy; }
			set
			{
				if (_locationAccuracy != value)
				{
					NotifyPropertyChanging("LocationAccuracy");
					_locationAccuracy = value;
					NotifyPropertyChanged("LocationAccuracy");
				}
			}
		}

		private double _locationX;
		[Column]
		public double LocationX
		{
			get { return _locationX; }
			set
			{
				if (_locationX != value)
				{
					NotifyPropertyChanging("LocationX");
					_locationX = value;
					NotifyPropertyChanged("LocationX");
				}
			}
		}

		private double _locationY;
		[Column]
		public double LocationY
		{
			get { return _locationY; }
			set
			{
				if (_locationY != value)
				{
					NotifyPropertyChanging("LocationY");
					_locationY = value;
					NotifyPropertyChanged("LocationY");
				}
			}
		}

		private double _locationZ;
		[Column]
		public double LocationZ
		{
			get { return _locationZ; }
			set
			{
				if (_locationZ != value)
				{
					NotifyPropertyChanging("LocationZ");
					_locationZ = value;
					NotifyPropertyChanged("LocationZ");
				}
			}
		}

		private string _operatingSystem;
		[Column]
		public string OperatingSystem
		{
			get { return _operatingSystem; }
			set
			{
				if (_operatingSystem != value)
				{
					NotifyPropertyChanging("OperatingSystem");
					_operatingSystem = value;
					NotifyPropertyChanged("OperatingSystem");
				}
			}
		}

		private string _operatingSystemVersion;
		[Column]
		public string OperatingSystemVersion
		{
			get { return _operatingSystemVersion; }
			set
			{
				if (_operatingSystemVersion != value)
				{
					NotifyPropertyChanging("OperatingSystemVersion");
					_operatingSystemVersion = value;
					NotifyPropertyChanged("OperatingSystemVersion");
				}
			}
		}

		private string _operatingSystemVersionName;
		[Column]
		public string OperatingSystemVersionName
		{
			get { return _operatingSystemVersionName; }
			set
			{
				if (_operatingSystemVersionName != value)
				{
					NotifyPropertyChanging("OperatingSystemVersionName");
					_operatingSystemVersionName = value;
					NotifyPropertyChanged("OperatingSystemVersionName");
				}
			}
		}

		private string _operatorCode;
		[Column]
		public string OperatorCode
		{
			get { return _operatorCode; }
			set
			{
				if (_operatorCode != value)
				{
					NotifyPropertyChanging("OperatorCode");
					_operatorCode = value;
					NotifyPropertyChanged("OperatorCode");
				}
			}
		}

		private string _operatorConnectionType;
		[Column]
		public string OperatorConnectionType
		{
			get { return _operatorConnectionType; }
			set
			{
				if (_operatorConnectionType != value)
				{
					NotifyPropertyChanging("OperatorConnectionType");
					_operatorConnectionType = value;
					NotifyPropertyChanged("OperatorConnectionType");
				}
			}
		}

		private string _operatorName;
		[Column]
		public string OperatorName
		{
			get { return _operatorName; }
			set
			{
				if (_operatorName != value)
				{
					NotifyPropertyChanging("OperatorName");
					_operatorName = value;
					NotifyPropertyChanged("OperatorName");
				}
			}
		}

		private bool _isPosted;
		[Column]
		public bool Posted
		{
			get { return _isPosted; }
			set
			{
				if (_isPosted != value)
				{
					NotifyPropertyChanging("Posted");
					_isPosted = value;
					NotifyPropertyChanged("Posted");
				}
			}
		}

		private int _sdkType;
		[Column]
		public int SDKType
		{
			get { return _sdkType; }
			set
			{
				if (_sdkType != value)
				{
					NotifyPropertyChanging("SDKType");
					_sdkType = value;
					NotifyPropertyChanged("SDKType");
				}
			}
		}

		private string _sdkVersion;
		[Column]
		public string SDKVersion
		{
			get { return _sdkVersion; }
			set
			{
				if (_sdkVersion != value)
				{
					NotifyPropertyChanging("SDKVersion");
					_sdkVersion = value;
					NotifyPropertyChanged("SDKVersion");
				}
			}
		}

		private int _sessionRestartTime;
		[Column]
		public int SessionRestartTime
		{
			get { return _sessionRestartTime; }
			set
			{
				if (_sessionRestartTime != value)
				{
					NotifyPropertyChanging("SessionRestartTime");
					_sessionRestartTime = value;
					NotifyPropertyChanged("SessionRestartTime");
				}
			}
		}

		private string _userId;
		[Column]
		public string UserId
		{
			get { return _userId; }
			set
			{
				if (_userId != value)
				{
					NotifyPropertyChanging("UserId");
					_userId = value;
					NotifyPropertyChanged("UserId");
				}
			}
		}

		private EntitySet<StoredEvent> _events;

		[Association(Storage = "_events", OtherKey = "_profileId", ThisKey = "ProfileId")]
		public EntitySet<StoredEvent> Events
		{
			get { return this._events; }
			set { this._events.Assign(value); }
		}

		// Version column aids update performance.
		[Column(IsVersion = true)]
		private Binary _version;

		#endregion

		public StoredProfile()
		{
			_events = new EntitySet<StoredEvent>(
				new Action<StoredEvent>(this.attachEvent),
				new Action<StoredEvent>(this.detachEvent)
				);
		}

		public StoredProfile(BangoProfile bProfile)
			: this()
		{
			SDKType = bProfile.SDKType;
			SDKVersion = bProfile.SDKVersion;
			ApplicationId = bProfile.ApplicationId;
			ApplicationType = bProfile.ApplicationType;
			ApplicationChannel = bProfile.ApplicationChannel;
			ApplicationVersion = bProfile.ApplicationVersion;
			UserId = bProfile.UserId;
			ConnectionType = bProfile.ConnectionType;
			IsRoaming = bProfile.IsRoaming;
			LocationSource = bProfile.LocationSource;
			LocationZ = bProfile.LocationZ;
			LocationY = bProfile.LocationY;
			LocationX = bProfile.LocationX;
			LocationAccuracy = bProfile.LocationAccuracy;
			SessionRestartTime = bProfile.SessionRestartTime;
			OperatorCode = bProfile.OperatorCode;
			OperatorConnectionType = bProfile.OperatorConnectionType;
			OperatorName = bProfile.OperatorName;
			OperatingSystemVersion = bProfile.OperatingSystemVersion;
			DeviceMake = bProfile.DeviceMake;
			DeviceModel = bProfile.DeviceModel;
			DeviceVersion = bProfile.DeviceVersion;
			Posted = bProfile.Posted;
			CountryISO = bProfile.CountryISO;
			DeviceBrand = bProfile.DeviceBrand;
			LocationCountryISO = bProfile.LocationCountryISO;
			LocationRegion = bProfile.LocationRegion;
			LocationTown = bProfile.LocationTown;
			OperatingSystemVersionName = bProfile.OperatingSystemVersionName;

			foreach (BangoEvent bEvent in bProfile.Events)
			{
				Events.Add(new StoredEvent(bEvent));
			}
		}

		private void attachEvent(StoredEvent thisEvent)
		{
			NotifyPropertyChanging("StoredEvent");
			thisEvent.Profile = this;
		}

		private void detachEvent(StoredEvent thisEvent)
		{
			NotifyPropertyChanging("StoredEvent");
			thisEvent.Profile = null;
		}

		public void UpdatePostedEvents()
		{
			this.Posted = true;
			this.IsPosting = false;

			foreach (StoredEvent evnt in this.Events)
			{
				evnt.Posted = true;
			}

			BangoViewModel.UpdatePostedProfile(this);

		}

		// Return BangoProfile with unposted events
		public BangoProfile GetPostProfile()
		{
			BangoProfile lProfile = new BangoProfile(
								ProfileId,
								SDKType,
								SDKVersion,
								ApplicationId,
								ApplicationType,
								ApplicationChannel,
								ApplicationVersion,
								UserId,
								ConnectionType,
								SessionRestartTime,
								IsRoaming,
								LocationSource,
								LocationZ,
								LocationY,
								LocationX,
								LocationAccuracy,
								OperatorCode,
								OperatorName,
								CountryISO,
								BangoConstants.HARD_CODED_DEVICE_BUILD_BRAND,
								DeviceMake,
								DeviceModel,
								BangoConstants.HARD_CODED_DEVICE_BUILD_PRODUCT,
								OperatingSystemVersion,
								DeviceVersion,
								OperatorConnectionType,
								BangoConstants.HARD_CODED_SIM_OPERATOR
							);

			foreach (StoredEvent ev in this.Events)
			{
				if (!ev.Posted)
				{
					lProfile.Events.Add(ev.GetBangoEvent());
				}
			}

			return lProfile;
		}

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		// Used to notify that a property changed
		private void NotifyPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
			}
		}

		#endregion

		#region INotifyPropertyChanging Members

		public event PropertyChangingEventHandler PropertyChanging;

		// Used to notify that a property is about to change
		private void NotifyPropertyChanging(string propertyName)
		{
			if (PropertyChanging != null)
			{
				PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
			}
		}

		#endregion
	}

	[Table]
	public class StoredEvent : INotifyPropertyChanged, INotifyPropertyChanging
	{

		#region Columns and Associations

		private int _eventId;
		[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
		public int EventId
		{
			get { return _eventId; }
			set
			{
				if (_eventId != value)
				{
					NotifyPropertyChanging("EventId");
					_eventId = value;
					NotifyPropertyChanged("EventId");
				}
			}
		}
		
		[Column]
		internal int _profileId;
		private EntityRef<StoredProfile> _profile;
		[Association(Storage = "_profile", ThisKey = "_profileId", OtherKey = "ProfileId", IsForeignKey = true)]
		public StoredProfile Profile
		{
			get { return _profile.Entity; }
			set
			{
				NotifyPropertyChanging("Profile");
				_profile.Entity = value;

				if (value != null)
				{
					_profileId = value.ProfileId;
				}
				NotifyPropertyChanging("Profile");
			}
		}

		private string _connectionType;
		[Column]
		public string ConnectionType
		{
			get { return _connectionType; }
			set
			{
				if (_connectionType != value)
				{
					NotifyPropertyChanging("ConnectionType");
					_connectionType = value;
					NotifyPropertyChanged("ConnectionType");
				}
			}
		}

		private string _errorId;
		[Column]
		public string ErrorId
		{
			get { return _errorId; }
			set
			{
				if (_errorId != value)
				{
					NotifyPropertyChanging("ErrorId");
					_errorId = value;
					NotifyPropertyChanged("ErrorId");
				}
			}
		}

		private int _errorLevel;
		[Column]
		public int ErrorLevel
		{
			get { return _errorLevel; }
			set
			{
				if (_errorLevel != value)
				{
					NotifyPropertyChanging("ErrorLevel");
					_errorLevel = value;
					NotifyPropertyChanged("ErrorLevel");
				}
			}
		}

		private string _eventDetail;
		[Column]
		public string EventDetail
		{
			get { return _eventDetail; }
			set
			{
				if (_eventDetail != value)
				{
					NotifyPropertyChanging("EventDetail");
					_eventDetail = value;
					NotifyPropertyChanged("EventDetail");
				}
			}
		}

		private string _eventName;
		[Column]
		public string EventName
		{
			get { return _eventName; }
			set
			{
				if (_eventName != value)
				{
					NotifyPropertyChanging("EventName");
					_eventName = value;
					NotifyPropertyChanged("EventName");
				}
			}
		}

		private string _eventValue;
		[Column]
		public string EventValue
		{
			get { return _eventValue; }
			set
			{
				if (_eventValue != value)
				{
					NotifyPropertyChanging("EventValue");
					_eventValue = value;
					NotifyPropertyChanged("EventValue");
				}
			}
		}

		private string _operatorConnectionType;
		[Column]
		public string OperatorConnectionType
		{
			get { return _operatorConnectionType; }
			set
			{
				if (_operatorConnectionType != value)
				{
					NotifyPropertyChanging("OperatorConnectionType");
					_operatorConnectionType = value;
					NotifyPropertyChanged("OperatorConnectionType");
				}
			}
		}

		private bool _isPosted;
		[Column]
		public bool Posted
		{
			get { return _isPosted; }
			set
			{
				if (_isPosted != value)
				{
					NotifyPropertyChanging("Posted");
					_isPosted = value;
					NotifyPropertyChanged("Posted");
				}
			}
		}

		private string _eventLocalTime;
		[Column]
		public string EventLocalTime
		{
			get { return _eventLocalTime; }
			set
			{
				if (_eventLocalTime != value)
				{
					NotifyPropertyChanging("EventLocalTime");
					_eventLocalTime = value;
					NotifyPropertyChanged("EventLocalTime");
				}
			}
		}

		private string _eventTime;
		[Column]
		public string EventTime
		{
			get { return _eventTime; }
			set
			{
				if (_eventTime != value)
				{
					NotifyPropertyChanging("EventTime");
					_eventTime = value;
					NotifyPropertyChanged("EventTime");
				}
			}
		}


		private EntitySet<StoredEventParameter> _eventParameters;
		[Association(Storage = "_eventParameters", OtherKey = "_eventId", ThisKey = "EventId")]
		public EntitySet<StoredEventParameter> EventParameters
		{
			get { return this._eventParameters; }
			set { this._eventParameters.Assign(value); }
		}

		// Version column aids update performance.
		[Column(IsVersion = true)]
		private Binary _version;

		#endregion

		#region Constructors

		public StoredEvent()
		{
			_eventParameters = new EntitySet<StoredEventParameter>(
				new Action<StoredEventParameter>(this.attachEventParameter),
				new Action<StoredEventParameter>(this.detachEventParameter)
				);
		}
		
		public StoredEvent(BangoEvent bangoEvent)
			: this()
		{
			ConnectionType = bangoEvent.ConnectionType;
			ErrorId = bangoEvent.ErrorId;
			ErrorLevel = bangoEvent.ErrorLevel;
			EventName = bangoEvent.EventName;
			EventDetail = bangoEvent.EventDetail;
			EventValue = bangoEvent.EventValue;
			EventTime = bangoEvent.EventTime;
			EventLocalTime = bangoEvent.EventLocalTime;
			OperatorConnectionType = bangoEvent.OperatorConnectionType;
			Posted = bangoEvent.Posted;

			EventParameters = new EntitySet<StoredEventParameter>();            
			
			foreach (BangoEventParameter bEventParam in bangoEvent.EventParameters)
			{
				EventParameters.Add(new StoredEventParameter(bEventParam));
			}
		}

		#endregion

		private void attachEventParameter(StoredEventParameter thisEventParameter)
		{
			NotifyPropertyChanging("StoredEventParameter");
			thisEventParameter.Event = this;
		}

		private void detachEventParameter(StoredEventParameter thisEventParameter)
		{
			NotifyPropertyChanging("StoredEventParameter");
			thisEventParameter.Event = null;
		}

		public BangoEvent GetBangoEvent()
		{
			List<BangoEventParameter> evParams = new List<BangoEventParameter>();

			foreach (StoredEventParameter ev in this.EventParameters)
			{
				evParams.Add(ev.GetEventParameter());
			}

			return  new BangoEvent(
					Profile.ProfileId,
					EventId,
					ConnectionType,
					OperatorConnectionType,
					ErrorLevel,
					EventName,
					EventDetail,
					EventValue,
					ErrorId,
					EventTime,
					EventLocalTime,
					evParams
					);
		}

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		// Used to notify that a property changed
		private void NotifyPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
			}
		}

		#endregion

		#region INotifyPropertyChanging Members

		public event PropertyChangingEventHandler PropertyChanging;

		// Used to notify that a property is about to change
		private void NotifyPropertyChanging(string propertyName)
		{
			if (PropertyChanging != null)
			{
				PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
			}
		}

		#endregion
	}
	
	[Table]
	public class StoredEventParameter : INotifyPropertyChanged, INotifyPropertyChanging
	{    

		#region Columns And Associations

		private int _eventParameterId;
		[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
		public int EventParameterId
		{
			get { return _eventParameterId; }
			set
			{
				if (_eventParameterId != value)
				{
					NotifyPropertyChanging("EventParameterId");
					_eventParameterId = value;
					NotifyPropertyChanged("EventParameterId");
				}
			}
		}

		[Column]
		internal int _eventId;
		private EntityRef<StoredEvent> _event;
		[Association(Storage = "_event", ThisKey = "_eventId", OtherKey = "EventId", IsForeignKey = true, DeleteOnNull = true)]
		public StoredEvent Event
		{
			get { return _event.Entity; }
			set
			{
				NotifyPropertyChanging("Event");
				_event.Entity = value;

				if (value != null)
				{
					_eventId = value.EventId;
				}
				NotifyPropertyChanged("Event");
			}
		}

		private string _parameterName;
		[Column]
		public string ParameterName
		{
			get { return _parameterName; }
			set
			{
				if (_parameterName != value)
				{
					NotifyPropertyChanging("ParameterName");
					_parameterName = value;
					NotifyPropertyChanged("ParameterName");
				}
			}
		}

		private string _parameterValue;
		[Column]
		public string ParameterValue
		{
			get { return _parameterValue; }
			set
			{
				if (_parameterValue != value)
				{
					NotifyPropertyChanging("ParameterValue");
					_parameterValue = value;
					NotifyPropertyChanged("ParameterValue");
				}
			}
		}

		// Version column aids update performance.
		[Column(IsVersion = true)]
		private Binary _version;

		#endregion

		#region Constructors 

		public StoredEventParameter()
		{
		}

		public StoredEventParameter(BangoEventParameter bangoEventParameter)
			: this()
		{
			ParameterName = bangoEventParameter.Name;
			ParameterValue = bangoEventParameter.Value;
		}


		public StoredEventParameter(String parameterName, String parameterValue)
			: this()
		{
			ParameterName = parameterName;
			ParameterValue = parameterValue;
		}
		
		#endregion

		public BangoEventParameter GetEventParameter()
		{
			return new BangoEventParameter(ParameterName, ParameterValue);
		}

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		// Used to notify that a property changed
		private void NotifyPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
			}
		}

		#endregion

		#region INotifyPropertyChanging Members

		public event PropertyChangingEventHandler PropertyChanging;

		// Used to notify that a property is about to change
		private void NotifyPropertyChanging(string propertyName)
		{
			if (PropertyChanging != null)
			{
				PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
			}
		}

		#endregion

	}
}
